/**************************************************************
  > File Name: 435.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月07日 星期一 15时21分52秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BIG 666666

int eraseOverlapIntervals(int **intervals, int intervalsSize)
{
	int *indexes = (int *)calloc(intervalsSize,sizeof(int));
	int *flag = (int *)calloc(intervalsSize,sizeof(int));
	int i, j, tmp;
	int min, right;
	int k = 0;
	int count = 1;
	
	for (j = 0; j < intervalsSize; j++)
	{
		min = BIG;
		for (i = 0; i < intervalsSize; i++)
		{
			if (min > intervals[i][1] && flag[i] != 1)
			{
				min = intervals[i][1];
				indexes[k] = i;
				tmp = i;
			}

		}
	   	flag[tmp] = 1;	
		k++;
	}
	
	right = intervals[indexes[0]][1];
	for (i = 1; i < intervalsSize; i++)
	{
		if (intervals[indexes[i]][0] >= right)
		{
			count++;
			right = intervals[indexes[i]][1];
		}
	}
	return intervalsSize - count;
}

int main(int argc,char **argv)
{
	int arr[2][2] = {{1,2},{2,3}};	
	int *a[2];
	int ret;

	for (int i = 0; i < 2; i++)
	{
		a[i] = arr[i];
	}
	ret = eraseOverlapIntervals(a, 2);
	printf("%d\n",ret);
	
    exit(0);
}
